home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 624 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  2.3 KB

  1. Path: chronicle.mti.sgi.com!austern
  2. From: clamage@Eng.Sun.COM (Steve Clamage)
  3. Newsgroups: comp.std.c++
  4. Subject: Re: Single-line comment and line continuation
  5. Date: 04 Mar 1996 11:22:32 PST
  6. Organization: Sun Microsystems Inc.
  7. Approved: austern@isolde.mti.sgi.com
  8. Message-ID: <4hffkm$3f0@engnews1.Eng.Sun.COM>
  9. References: <313B3175.331A@strata3d.com>
  10. Reply-To: clamage@Eng.Sun.COM
  11. NNTP-Posting-Host: isolde.mti.sgi.com
  12. X-Original-Date: 4 Mar 1996 19:17:42 GMT
  13. X-Auth: PGPMoose V1.1 PGP comp.std.c++
  14.     iQBVAwUBMTtDJky4NqrwXLNJAQHTvAIAmKLPL67LhQ5Vhd804vESSjUeTpHSd4GY
  15.     REw/ufuzIrPW69x5CRk9Lia6DgZKAw2kt4n4xmO3odHlbohIzVNA8A==
  16.     =hiGH
  17. Originator: austern@isolde.mti.sgi.com
  18.  
  19. In article 331A@strata3d.com, Bret Pehrson <BretP@strata3d.com> writes:
  20. >I just ran across something in my C++ compiler dealing with single line 
  21. >comments and the line continuation token:
  22. >
  23. > if ((ch[0] == '\\') && (ch[1] == '\\'))  //look for initial \\
  24. > {
  25. >   ...
  26. >
  27. >This, under my compiler implementation will choke because of the line 
  28. >continuation token, '\' at the end of the comment.
  29. >
  30. >Can someone please look in their copy of the current C++ 'standard' and tell 
  31. >me if this is correct?
  32.  
  33. Yes, it is a consequence of the phases of translation. Escaped newlines
  34. are handled by pasting lines together before comments are removed, the
  35. same as in C. (When C adds '//' comments, I expect it to have the same
  36. behavior.)
  37.  
  38. The phases of translation were very carefully worked out by the ANSI C
  39. committee for the C standard, and any change causes various things to break
  40. or otherwise behave strangely. The fragility is due to interactions among
  41.     trigraphs
  42.     escaped newlines
  43.     escaped characters in strings or character constants
  44.     macro expansion.
  45.  
  46. In C++, simply don't use '//' comments on any line that ends with an
  47. escaped newline (including macro definitions!). In your example, it would
  48. make the comment more readable IMHO if you put the '\\' in quotes anyway,
  49. and would eliminate the problem.
  50.  
  51. ---
  52. Steve Clamage, stephen.clamage@eng.sun.com
  53. ---
  54. [ comp.std.c++ is moderated.  To submit articles: Try just posting with your 
  55.                 newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  56.   comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  57.   Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  58.   Comments? mailto:std-c++-request@ncar.ucar.edu 
  59. ]
  60.